package de.tabuma.pm.project.view;

import de.tabuma.pm.project.entity.*;
import de.tabuma.pm.projectnavigation.view.list;
import de.tabuma.pm.security.*;
import de.tabuma.lib.tabumaview;

import java.io.PrintWriter;
import java.util.*;

import de.tabuma.pm.*;
import de.tabuma.pm.design.DesignController;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author alefen
 */
public class view extends tabumaview {

    public view(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        
        Project project = (Project) request.getAttribute(constants.paramProject);
        String projectnavigation = "projectnavigation";
        
        String toList = "back to project list";
        
        update update = new update(this.getServlet(), this.getParameter());
        update.processRequest(context, request, response, out);

        String projectView = "projectView";

        out.println("<div class=\"contentContent\">");

        out.println("\t<div class=\"col1\">");
        out.println("\t\t<a href=\"projectview?projectId=" + project.getId() + "\" target=\"_blank\">" + projectView + "</a>");
        out.println("\t</div>");

        out.println("\t<div class=\"col2\">");
        out.println("\t\t<form action=\""+this.getServlet()+"\">");
        this.getParameter().put(constants.paramAction, ""+constants.ACTION_LIST);
        out.println(this.getHiddenAsAttribute());
        out.println("\t\t\t<input type=\"submit\" class=\"button\" value=\""+toList+"\"/>");
        out.println("\t\t</form>");
        out.println("\t</div>");
        out.println("</div>");
        out.println("<div class=\"contentContent\"></div>");
        
        this.getParameter().put(constants.paramAction, ""+constants.ACTION_OVERVIEW);
        Hashtable hash = (Hashtable) this.getParameter().clone();
        hash.put(constants.projectId, ""+project.getId());

        out.println("\t\t<div class=\"contentBoxed\">");
        out.println("\t\t\t<div class=\"contentHeader\"><a name=\""+constants.ProjectNavigationA+"\">project konfiguration</a></div>");
        out.println("\t\t</div>");

        int projectParamNavigation = constants.PROJECT_ACTION_PARAM_NAVIGATION;
        if(request.getAttribute(constants.PROJECT_ACTION_PARAM)!=null) {
            projectParamNavigation = Integer.valueOf(""+request.getAttribute(constants.PROJECT_ACTION_PARAM)).intValue();
        }

        hash.put(constants.PROJECT_ACTION_PARAM, "" + projectParamNavigation);

        String externalProject = "external projects";
        String projectDesign = "project design";
        String securityProvider = "security provider";

        out.println("\t<div class=\"contentContent\">");
        out.println("\t\t<div class=\"contentBoxed\">");

        out.println("\t<div class=\"contentContent\">");
        out.println("\t\t<div class=\"tab\">");
        

        String linkNavigation = this.getServlet()+"?"+constants.projectId+"="+project.getId()+"&amp;"+this.getLinkAsAttribute()+"&amp;"+constants.PROJECT_ACTION_PARAM+"="+constants.PROJECT_ACTION_PARAM_NAVIGATION+"#"+constants.ProjectNavigationA;
        String linkExternalProject = this.getServlet()+"?"+constants.projectId+"="+project.getId()+"&amp;"+this.getLinkAsAttribute()+"&amp;"+constants.PROJECT_ACTION_PARAM+"="+constants.PROJECT_ACTION_PARAM_EXTERNAL_PROJECT+"#"+constants.ProjectNavigationA;
        String linkProjectDesign = this.getServlet()+"?"+constants.projectId+"="+project.getId()+"&amp;"+this.getLinkAsAttribute()+"&amp;"+constants.PROJECT_ACTION_PARAM+"="+constants.PROJECT_ACTION_PARAM_PROJECT_DESIGN+"#"+constants.ProjectNavigationA;
        String linkSecurityProvider = this.getServlet()+"?"+constants.projectId+"="+project.getId()+"&amp;"+this.getLinkAsAttribute()+"&amp;"+constants.PROJECT_ACTION_PARAM+"="+constants.PROJECT_ACTION_PARAM_SECURITY_PROVIDER+"#"+constants.ProjectNavigationA;

        out.println("\t\t\t<div class=\"tabelementbeginnclose\"></div>");
        if(projectParamNavigation==constants.PROJECT_ACTION_PARAM_NAVIGATION) {
            out.println("\t\t\t<div class=\"tabelementopen\"><a href=\""+linkNavigation+"\">"+projectnavigation+"</a></div>");
        }
        else {
            out.println("\t\t\t<div class=\"tabelementclose\"><a href=\""+linkNavigation+"\">"+projectnavigation+"</a></div>");
        }
        if(projectParamNavigation==constants.PROJECT_ACTION_PARAM_EXTERNAL_PROJECT) {
            out.println("\t\t\t<div class=\"tabelementopen\"><a href=\""+linkExternalProject+"\">"+externalProject+"</a></div>");
        }
        else {
            out.println("\t\t\t<div class=\"tabelementclose\"><a href=\""+linkExternalProject+"\">"+externalProject+"</a></div>");
        }
        if(projectParamNavigation==constants.PROJECT_ACTION_PARAM_PROJECT_DESIGN) {
            out.println("\t\t\t<div class=\"tabelementopen\"><a href=\""+linkProjectDesign+"\">"+projectDesign+"</a></div>");
        }
        else {
            out.println("\t\t\t<div class=\"tabelementclose\"><a href=\""+linkProjectDesign+"\">"+projectDesign+"</a></div>");
        }
        if(projectParamNavigation==constants.PROJECT_ACTION_PARAM_SECURITY_PROVIDER) {
            out.println("\t\t\t<div class=\"tabelementopen\"><a href=\""+linkSecurityProvider+"\">"+securityProvider+"</a></div>");
        }
        else {
            out.println("\t\t\t<div class=\"tabelementclose\"><a href=\""+linkSecurityProvider+"\">"+securityProvider+"</a></div>");
        }
        out.println("\t\t\t<div class=\"tabelementbeginnclose\"></div>");
        out.println("\t\t</div>");
        
        switch(projectParamNavigation) {
            case constants.PROJECT_ACTION_PARAM_EXTERNAL_PROJECT:
                        de.tabuma.pm.externalproject.view.view epv = new de.tabuma.pm.externalproject.view.view(this.getServlet(), hash);
                        epv.processRequest(context, request, response, out);
                        out.println("\t</div>");
                        break;

            case constants.PROJECT_ACTION_PARAM_SECURITY_PROVIDER:
                        out.println("\t</div>");
                        SecurityProviderInstanceController spic = new SecurityProviderInstanceController(this.getServlet(), hash);
                        spic.navigate(context, request, response, out);

                        break;

            case constants.PROJECT_ACTION_PARAM_PROJECT_DESIGN:
                        out.println("\t</div>");
                        DesignController dc = new DesignController(this.getServlet(), hash);
                        dc.navigate(context, request, response, out);
                        break;

            default:    Hashtable hash1 = (Hashtable) this.getParameter().clone();
                        list lpnv = new list(this.getServlet(), hash1);
                        lpnv.processRequest(context, request, response, out);
                        out.println("\t</div>");
                        break;

        }
        
        out.println("\t</div>");
        out.println("\t</div>");
    }
}